package com.leyou.item.controller;
/*
import com.leyou.common.page.PageResult;
import com.leyou.item.domian.Brand;
import com.leyou.item.dto.BrandDTO;
import com.leyou.item.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping
public class BrandController {
    @Autowired
    private BrandService brandService;
    //1,请求类型 get
    //2，请求的url ：看文档（GET /brand/page?key=&page=1&rows=5&sortBy=id&desc=false）
    //3，请求参数 ：（key 搜索关键词 否 String
    //             page 当前页码 否 Integer 1
    //             rows 每页显示条数 否 Integer 10
    //             sortBy 排序字段 否 String
    //             desc 是否降序 否 Boolean false）
    //4，返回的的结果  ：json数据 （"id": 1528,
    //                           "name": "LG",
    //                           "image": "",
    //                           "letter": "L"
    //                           "total": 168,
    //                           "totalPage": 56）

    *//**
     * 品牌的查询操作
     * @param key
     * @param page
     * @param rows
     * @param sortBy
     * @param desc
     * @return
     *//*
    @GetMapping("/brand/page")
    public ResponseEntity<PageResult<BrandDTO>>findBrandByPage
            (@RequestParam(value = "key",required= false) String key,
             @RequestParam(value = "page",defaultValue= "1") Integer page,
             @RequestParam(value = "page",defaultValue= "5") Integer rows,
             @RequestParam(value = "sortBy",required = false) String sortBy,
             @RequestParam(value = "desc",defaultValue = "false")Boolean desc){
        PageResult<BrandDTO> brandByPage = brandService.findBrandByPage(page, rows, key, sortBy, desc);
        return ResponseEntity.ok(brandByPage);


    }

    //1,请求类型 post
    //2，请求的url ：看文档（POST /brand）
    //3，请求参数 ：（name 品牌名称 是 String
    //image 品牌logo 否 String
    //cids 分类id集合，如77,84 是 List
    //letter 首字母 是 String
    //4，返回的的结果 无

    @PostMapping("/brand")
    public ResponseEntity<Void>saveBrand(BrandDTO brandDTO, List<Long>cids){
        brandService.saveBrand(brandDTO,cids);
        return ResponseEntity.status(HttpStatus.CREATED).build();



    }*/


import com.leyou.common.constant.PageResult;
import com.leyou.item.dto.BrandDTO;
import com.leyou.item.dto.SpuDTO;
import com.leyou.item.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 根据分页查询所有品牌
     * @param key
     * @param page
     * @param rows
     * @param sortBy
     * @param desc
     * @return
     */
    @GetMapping("/brand/page")
    public ResponseEntity<PageResult<BrandDTO>> brandPageQuery(@RequestParam(value = "key", required = false) String key,
                                                               @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                               @RequestParam(value = "rows", defaultValue = "5") Integer rows,
                                                               @RequestParam(value = "sortBy", required = false) String sortBy,
                                                               @RequestParam(value = "desc", required = false) Boolean desc){
        PageResult<BrandDTO> pageResult = brandService.brandPageQuery(key, page, rows, sortBy, desc);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * //根据品牌id查询品牌对象
     * @param id
     * @return
     */
    @GetMapping("/brand/{id}")
    public ResponseEntity<BrandDTO>findBrandById(@PathVariable("id")Long id){
        BrandDTO brandDTO=brandService.findBrandById(id);
        return ResponseEntity.ok(brandDTO);
    }

    /**
     * @param brandDTO
     * @param cids @RequestParam("cids")注解可以将76,79格式的数据直接转成list
     * @return
     */
    @PostMapping("/brand")
    public ResponseEntity<Void> saveBrand(BrandDTO brandDTO, @RequestParam("cids")List<Long> cids){
        brandService.saveBrand(brandDTO, cids);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }



    /**
     * //根据分类id查询品牌列表
     * @param id
     * @return
     */
    @GetMapping("/brand/of/category")
    public ResponseEntity<List<BrandDTO>>findBrandByCid(@RequestParam("id")Long id){
        List<BrandDTO>list=brandService.findBrandByCid(id);
        return ResponseEntity.ok(list);


    }


}





